﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using GalaSoft.MvvmLight.Ioc;
using Tisbi.LawFirm.DAL.Models;

namespace Tisbi.LawFirm.BL.Services.Implementation.Mock
{
    public class MockEmployeeServiceAgent : MockServiceAgentBase<Employees>, IEmployeesServiceAgent
    {
        private List<Employees> mockEmployees;
        private ICaseServiceAgent _caseServiceAgent;

        public MockEmployeeServiceAgent()
        {
            // Mock Employees
            mockEmployees = new List<Employees>
            {
                new Employees
                {
                    Id = 1, 
                    ShortFio = "Иван Иванович",
                    Role = Role.User,
                    EmployeeType = EmployeeType.Юрист,
                    Login = "ivanov",
                    Password = "Password",
                    FullFio = "Иванов Иван Иванович",
                    Gender = Gender.Мужской,
                    DobTime = new DateTime(1988, 1, 1),
                    PlaseOfBirth = "Москва",
                    Address = "420138, Россия, Татарстан, гор. Казань, ул. Дубравная, д. 51, кв. 116",
                    PasportSeries = 1234,
                    PasportNumber = 445599,
                    PasportStartOn = new DateTime(2000, 8, 12),
                    PasportWhoGet = "Отделом УФМС РФ по городу Москве",
                    PasportNumberOfSubdivision = "114-000"
                },
                new Employees
                {
                    Id = 2, 
                    ShortFio = "Марат Рашидович",
                    Role = Role.User,
                    EmployeeType = EmployeeType.Юрист,
                    Login = "marat",
                    Password = "Password",
                    FullFio = "Хусаинов Марат Рашидович",
                    Gender = Gender.Мужской,
                    DobTime = new DateTime(1970, 5, 20),
                    PlaseOfBirth = "Казань",
                    Address = "420124, Россия, Татарстан, гор. Казань, ул. Проспект-победы, д. 97, кв. 24",
                    PasportSeries = 5578,
                    PasportNumber = 468237,
                    PasportStartOn = new DateTime(2002, 4, 8),
                    PasportWhoGet = "Отделом УФМС РТ по городу Казани",
                    PasportNumberOfSubdivision = "116-000"
                },
                new Employees
                {
                    Id = 3, 
                    ShortFio = "Дмитрий Гришин",
                    Role = Role.User,
                    EmployeeType = EmployeeType.Юрист,
                    Login = "misha",
                    Password = "Password",
                    FullFio = "Гришин Дмитрий Дмитриевич",
                    Gender = Gender.Мужской,
                    DobTime = new DateTime(1989, 5, 20),
                    PlaseOfBirth = "Казань",
                    Address = "420129, Россия, Татарстан, гор. Казань, ул. Р.Зорге, д. 12, кв. 11",
                    PasportSeries = 6752,
                    PasportNumber = 235782,
                    PasportStartOn = new DateTime(2004, 6, 2),
                    PasportWhoGet = "Отделом УФМС РТ по городу Казани",
                    PasportNumberOfSubdivision = "110-000"
                }
            };
        }

        public override void GetItem(Action<List<Employees>, Exception> completed)
        {
            try
            {
                completed(mockEmployees, null);
            }
            catch (Exception ex)
            {
                completed(null, ex);
            }
        }

        public override void AddItem(Employees item, Action<Exception> completed)
        {
            mockEmployees.Add(item);
        }

        public override void RemoveItem(Employees item)
        {
            mockEmployees.Remove(item);
        }

        public override void Edit(Employees item, Action<Exception> completed)
        {
            MessageBox.Show("Edit not implemented");
        }

        public bool HasCases(int employeeId)
        {
            _caseServiceAgent = SimpleIoc.Default.GetInstance<ICaseServiceAgent>();

            bool has = false;
            _caseServiceAgent.GetCasesByEmployee(employeeId, (caseses, error) =>
            {
                if (error == null)
                {
                    has = caseses.Any();
                }
                else
                {
                    Notifyer.NotifyError("Unable to retrieve items", error);
                }
            });

            return has;
        }
    }
}